 package com.handong.handserialprogram.module.voice;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.handong.handserialprogram.R;
import com.handong.handserialprogram.constants.HttpConstant;
import com.handong.handserialprogram.model.MessageBean;
import com.handong.handserialprogram.module.base.BackStackFragment;
import com.handong.handserialprogram.service.PlayService;
import com.handong.handserialprogram.service.SignalRService;
import com.handong.handserialprogram.utils.AppCache;
import com.handong.handserialprogram.utils.AsyncHttpUtil;
import com.handong.handserialprogram.utils.CallBackUtil;
import com.handong.handserialprogram.utils.JLog;
import com.handong.handserialprogram.utils.SPUtil;
import com.handong.handserialprogram.utils.ViewUtil;
import com.handong.handserialprogram.voice.VoiceImpl;
import com.ilike.voicerecorder.widget.VoiceRecorderView;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;

import net.arvin.selector.SelectorHelper;
import net.arvin.selector.data.ConstantData;
import net.arvin.selector.utils.PSGlideUtil;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import static android.app.Activity.RESULT_OK;

//import zsoft.signala.hubs.HubConnection;


public class TestVoiceActivity extends BackStackFragment {

    protected VoiceRecorderView voiceRecorderView;
    protected ListView message_list;
    protected TextView tvRecorder,btnSendText;
    public String mMissionId;
    protected LinearLayout mRequestMissionTip;
    protected RelativeLayout mListItemContainer;
    protected  ImageView tvVoice,tvPhoto;
    protected EditText etTextBox;
    private VoiceImpl mVoiceImpl;
    private boolean isFirst=true;

    protected static final String TAG= TestVoiceActivity.class.getSimpleName();


    private List<MessageBean> voices;
    EaseMessageAdapter adapter;

    public TestVoiceActivity() {
    }

    public static TestVoiceActivity newInstance() {
        TestVoiceActivity fragment = new TestVoiceActivity();
        return fragment;
    }

    private class PlayServiceConnection implements ServiceConnection {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            final PlayService playService = ((PlayService.PlayBinder) service).getService();
            Log.d("onServiceConnected----", "onServiceConnected");
            AppCache.setPlayService(playService);
           // createAndJoinRoom(mMissionId,SPUtil.getStringValue(SPUtil.USER_NAME));
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
        }
    }

    private ArrayList<String> selectedPictures = new ArrayList<>();
    private ArrayList<String> selectedVideos = new ArrayList<>();

    PlayServiceConnection mPlayServiceConnection;
    @Override
    protected int getContentViewID() {
        return R.layout.activity_voice;
    }

//    public void selectPicture(View v) {
//
//            SelectorHelper.selectPictures(this.getActivity(), 9,
//                    true, ((VoiceActivity)this.getActivity()).selectedPictures, 1001);
//
//    }


    private SignalRService sService;
    private boolean mBound = false;
    private ServiceConnection mConnection;
    String ip = SPUtil.getStringValue(SPUtil.SERVER_IP);
    int port = SPUtil.getIntValue(SPUtil.FILE_PORT);

    @Override
    public void onDestroyView() {
        if (signalrBind) {
            getActivity().unbindService( mConnection);
            signalrBind=false;
        }
        if (playBind){
            getActivity().unbindService( mPlayServiceConnection);
            playBind=false;
        }
        super.onDestroyView();
    }

    public void GetList()
    {

        //voices = new ArrayList<>();

        RequestParams params = new RequestParams("visit", "GetChatList");
        params.put("missId",mMissionId);
        params.put("sys_companycode",SPUtil.getStringValue(SPUtil.LOGIN_CODE));
        AsyncHttpUtil.postRequest(params, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                //dismissLoadingDialog();
                mRequestMissionTip.setVisibility(View.VISIBLE);
                mListItemContainer.setVisibility(View.GONE);
                showShortToast("服务器无响应");
            }

            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                //JLog.d(TAG, "Upload Result:" + s);
                if (!TextUtils.isEmpty(s.toString())) {
                    try {
                        voices.clear();
                        JSONObject obj = new JSONObject(s);
                        if (obj.getBoolean(HttpConstant.RESPONSE_SUCCESS)) {
                            mRequestMissionTip.setVisibility(View.GONE);
                            mListItemContainer.setVisibility(View.VISIBLE);
                            //dismissLoadingDialog();

                            JSONArray jsonArray= obj.getJSONArray("uploadlist");
                            for (int c = 0; c <jsonArray.length(); c++) {
                                JSONObject item= jsonArray.getJSONObject(c);
                                final MessageBean bean = new MessageBean();
                                bean.datatype=item.getInt("datatype");
                                if (bean.datatype==0){
                                    bean.path =  item.getString("url");
                                }else{
                                    bean.path = "http://"+ip+":"+port + item.getString("url");
                                }
                                //bean.path = "http://"+ip+":"+port+item.getString("url");
                                bean.msg = item.getString("username");
                                bean.second = item.getInt("duringInt");
                                bean.time =item.getLong("timelong");
                                bean.iswaiting = false;

                                voices.add(bean);
                            }
                            //adapter.notifyDataSetChanged();
                            Bundle data = new Bundle();
                            Message message1 = new Message();
                            message1.setData(data);

                            updateDateHandler.sendMessage(message1);

                            //voiceRecorderView.scrollTo((int)voiceRecorderView.getX(),(int)voiceRecorderView.getY());
                            //voiceRecorderView.setVerticalScrollbarPosition(adapter.getCount());

                        } else {
                            showShortToast(obj.getString(HttpConstant.FAIL_REASON));
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                        showShortToast("服务器无响应");
                        mRequestMissionTip.setVisibility(View.VISIBLE);
                        mListItemContainer.setVisibility(View.GONE);
                    }
                }
            }
        });
    }
//    @Override
//    protected boolean onBackClicked() {
//        if (signalrBind) {
//            getActivity().unbindService( mConnection);
//            signalrBind=false;
//        }
//        if (playBind){
//            getActivity().unbindService( mPlayServiceConnection);
//            playBind=false;
//        }
//        return false;
//    }

    //private ServiceConnection conn1;

    boolean signalrBind=false;
    boolean playBind=false;

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void initViewByID(View contentView) {
        try {
            final Context context=this.getActivity();
            initHeaderLayout(R.string.voice_title);
            voices = new ArrayList<>();
            //startSignalR();

            mRequestMissionTip = (LinearLayout) findViewById(R.id.missionTipLayout);
            mListItemContainer = (RelativeLayout) findViewById(R.id.list_item_container);
            final Context activity = this.getActivity();
            mRequestMissionTip.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (AsyncHttpUtil.isNetworkConnected(activity)) {
                        //showLoadDialog("语音汇报列表加载中...");
                        showShortToast("正在重新连接服务器");
                        AppCache.getSignalRService().startSignalR(activity);
//                        AppCache.getSignalRService().startSignalR(context);
//                        AppCache.getSignalRService().createAndJoinRoom(mMissionId, SPUtil.getStringValue(SPUtil.USER_NAME));
                        //GetList();
                    } else {
                        openNetwork();
                    }
                }
            });




            final Activity content=this.getActivity();
            message_list = (ListView) findViewById(R.id.message_list);
            voiceRecorderView = (VoiceRecorderView) findViewById(R.id.voice_recorder);
            voiceRecorderView.setShowMoveUpToCancelHint("手指上滑，取消发送");
            voiceRecorderView.setShowReleaseToCancelHint("松开手指，取消发送");
            tvRecorder = (TextView) findViewById(R.id.tv_touch_recorder);
            tvVoice=(ImageView) findViewById(R.id.voice_btn);
            tvPhoto=(ImageView) findViewById(R.id.photo_btn);
            btnSendText=(TextView)findViewById(R.id.btn_send_text);
            etTextBox=(EditText)findViewById(R.id.text_content);
            tvPhoto.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    SelectorHelper.selectPicturesAndVideos(content, 9, true, selectedPictures,selectedVideos, 1001);
                }
            });
            btnSendText.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String text=etTextBox.getText().toString();
                    if (!text.equals("")) {
                        etTextBox.setText("");
                        RequestParams params = new RequestParams("visit", "Upload");

                        params.put("content", text);
                        etTextBox.setText("");
                        params.put("datatype", "0");
                        params.put("usertype","1");
                        AsyncHttpUtil.postRequest(params, new TextHttpResponseHandler() {
                            @Override
                            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                                showShortToast("服务器无响应");
                            }

                            @Override
                            public void onSuccess(int i, Header[] headers, String s) {
                                //JLog.d(TAG, "Upload Result:" + s);
                                if (!TextUtils.isEmpty(s.toString())) {
                                    try {
                                        JSONObject obj = new JSONObject(s);
                                        if (obj.getBoolean(HttpConstant.RESPONSE_SUCCESS)) {

                                            obj.put("datatype", "0");
                                            obj.put("username", SPUtil.getStringValue(SPUtil.USER_NAME));
                                            obj.put("companyname", SPUtil.getStringValue(SPUtil.LOGIN_CODE));
                                            obj.put("equipmentnum", SPUtil.getStringValue(SPUtil.PHONE_NAME));

                                            AppCache.getSignalRService().sendData(mMissionId, obj.toString());

//                                            bean.path = obj.getString();
//                                            bean.iswaiting=false;
//                                            adapter.notifyDataSetChanged();
                                            //showShortToast("上传中");
                                        } else {
                                            showShortToast(obj.getString(HttpConstant.FAIL_REASON));
                                        }
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                        showShortToast("服务器无响应");
                                    }
                                }
                            }
                        });
                    }
                }
            });
            tvVoice.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(tvRecorder.getVisibility()==View.GONE){
                        tvRecorder.setVisibility(View.VISIBLE);
                        tvVoice.setImageResource(R.drawable.text);
                        btnSendText.setVisibility(View.GONE);
                        etTextBox.setVisibility(View.GONE);
                        //etTextBox.

                    }else{
                        tvRecorder.setVisibility(View.GONE);
                        tvVoice.setImageResource(R.drawable.voice_btn);
                        etTextBox.setVisibility(View.VISIBLE);
                        btnSendText.setVisibility(View.VISIBLE);
                    }
                }
            });

            adapter = new EaseMessageAdapter(this.getActivity(), voices);
            message_list.setAdapter(adapter);
            adapter.setOnItemClickLister(new EaseMessageAdapter.onItemClickLister() {
                @Override
                public void onItemClick(ImageView imageView, String path, int position) {
                    if (AppCache.getPlayService() != null) {
                        AppCache.getPlayService().setImageView(imageView);
                        AppCache.getPlayService().stopPlayVoiceAnimation();
                        AppCache.getPlayService().play(path);
                    }
                }
            });

            Intent intent = new Intent();
            intent.setClass(this.getActivity(), SignalRService.class);
            mConnection = new ServiceConnection()
            {
                @Override
                public void onServiceConnected(ComponentName name, IBinder service)
                {
                    // We've bound to SignalRService, cast the IBinder and get SignalRService instance
                    SignalRService.LocalBinder binder = (SignalRService.LocalBinder) service;
//                    sService = binder.getService();
//                    sService.startSignalR(context);
//                    mBound = true;
//                    sService.createAndJoinRoom(mMissionId,SPUtil.getStringValue(SPUtil.USER_NAME));
//                    AppCache.setSignalRService(sService);

                }
                @Override
                public void onServiceDisconnected(ComponentName arg0)
                {
                    mBound = false;
                }
            };
            signalrBind=getActivity().bindService(intent, mConnection, Context.BIND_ADJUST_WITH_ACTIVITY);
//        AppCache.getSignalRService().setOnReconnectedListener(new CallBackUtil.OnReconnectedListener() {
//            @Override
//            public void onReconnected() {
//                AppCache.getSignalRService().createAndJoinRoom(mMissionId,SPUtil.getStringValue(SPUtil.USER_NAME));
//            }
//        });
            AppCache.getSignalRService().setOnReconnectingListener(new CallBackUtil.OnReconnectingListener() {
                @Override
                public void onReconnecting() {
////                mRequestMissionTip.setVisibility(View.VISIBLE);
////                mListItemContainer.setVisibility(View.GONE);
//                    GetList();
////                Runnable aa=  new Runnable() {
////                @Override
////              public void run() {
////
////                    AppCache.getSignalRService().startSignalR();
////                AppCache.getSignalRService().joinRoom(mMissionId,SPUtil.getStringValue(SPUtil.USER_NAME));
////                }
////            };
////                aa.run();
//
                    //AppCache.getSignalRService().DisConnected();
                    GetList();
                    AppCache.getSignalRService().joinRoom(mMissionId,SPUtil.getStringValue(SPUtil.USER_NAME));
                    AppCache.getSignalRService().Subscribe();
                    Bundle data = new Bundle();
                    data.putBoolean("isonline",true);
                    Message message1 = new Message();
                    message1.setData(data);

                    updateOnlieStateHandler.sendMessage(message1);
                }
            });
            AppCache.getSignalRService().setOnReconnectedListener(new CallBackUtil.OnReconnectedListener() {
                @Override
                public void onReconnected() {

                    Bundle data = new Bundle();
                    data.putBoolean("isonline",false);
                    Message message1 = new Message();
                    message1.setData(data);

                    updateOnlieStateHandler.sendMessage(message1);


                    //GetList();
                }
            });
            AppCache.getSignalRService().setOnReceiveListener(new CallBackUtil.OnReceiveListener() {
                @Override
                public void onReceive(String companyCode,String room, String message) {
                    if (!TextUtils.isEmpty(message)) {

                        try {
                            JSONObject obj = new JSONObject(message);
//                        final MessageBean bean = new MessageBean();
//                        bean.path = obj.getString("url");
//                        bean.msg = obj.getString("username");
//                        bean.second = obj.getInt("duringInt");
//                        bean.time =obj.getLong("timelong");
//                        bean.iswaiting = false;
//                        voices.add(bean);
//                        String catId = "123";
                            boolean isFind = false;
                            int datatype=obj.getInt("datatype");
                            if (obj.getString("username").equals(SPUtil.getStringValue(SPUtil.USER_NAME))) {
                                for (int i = 0; i < voices.size(); i++) {
                                    if (voices.get(i).path.equals("") && voices.get(i).msg.equals(SPUtil.getStringValue(SPUtil.USER_NAME))) {
                                        //列表中包含改元素，做逻辑
                                        voices.get(i).iswaiting = false;
                                        if (datatype==0){
                                            voices.get(i).path =  obj.getString("url");
                                        }else{
                                            voices.get(i).path = "http://"+ip+":"+port + obj.getString("url");
                                        }

                                        isFind = true;
                                    }
                                }
                            }
                            else
                            {
                                receiveMessageVoice();
                            }
                            if (!isFind) {
                                final MessageBean bean = new MessageBean();
                                if (datatype==0){
                                    bean.path =  obj.getString("url");
                                }else{
                                    bean.path = "http://"+ip+":"+port+ obj.getString("url");
                                }
                                bean.msg = obj.getString("username");
                                bean.second = obj.getInt("duringInt");
                                bean.time = obj.getLong("timelong");
                                bean.datatype=datatype;
                                bean.iswaiting = false;
                                voices.add(bean);
                            }
                            //if (voices)
                            Bundle data = new Bundle();
                            Message message1 = new Message();
                            message1.setData(data);

                            updateDateHandler.sendMessage(message1);
                            //adapter.notifyDataSetChanged();

                            //adapter.notifyAll();
                        } catch (JSONException e) {
                            e.printStackTrace();
                            showShortToast("服务器无响应");
                        }

                    }
                }
            });

            tvRecorder.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {

                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        if (AppCache.getPlayService().isPlaying) {
                            AppCache.getPlayService().stopPlayVoiceAnimation2();
                        }
                        tvRecorder.setText("松开 结束");
                    }


                    return voiceRecorderView.onPressToSpeakBtnTouch(v, event, new VoiceRecorderView.EaseVoiceRecorderCallback() {

                        @Override
                        public void onVoiceRecordComplete(String voiceFilePath, int voiceTimeLength, String fileName) throws FileNotFoundException {
                            Log.d("voiceFilePath=", voiceFilePath + "  time = " + voiceTimeLength);

                            final MessageBean bean = new MessageBean();
                            bean.path = "";
                            bean.msg = SPUtil.getStringValue(SPUtil.USER_NAME);
                            bean.second = voiceTimeLength;
                            bean.time = System.currentTimeMillis();
                            bean.datatype=1;
                            bean.iswaiting = true;
                            voices.add(bean);
                        Bundle data = new Bundle();
                        Message message1 = new Message();
                        message1.setData(data);

                        updateDateHandler.sendMessage(message1);
                           // adapter.notifyDataSetChanged();


                            RequestParams params = new RequestParams("visit", "Upload");
                            params.put("FileData", new File[]{new File(voiceFilePath)}, "audio/AMR", fileName);
                            params.put("duration", voiceTimeLength);
                            params.put("datatype","1");
                            AsyncHttpUtil.postRequest(params, new TextHttpResponseHandler() {
                                @Override
                                public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                                        showShortToast("服务器无响应");
                                }

                                @Override
                                public void onSuccess(int i, Header[] headers, String s) {
                                    JLog.d(TAG, "Upload Result:" + s);
                                    if (!TextUtils.isEmpty(s.toString())) {
                                        try {
                                            JSONObject obj = new JSONObject(s);
                                            if (obj.getBoolean(HttpConstant.RESPONSE_SUCCESS)) {

                                                obj.put("datatype","1");
                                                obj.put("username", SPUtil.getStringValue(SPUtil.USER_NAME));
                                                obj.put("companyname", SPUtil.getStringValue(SPUtil.LOGIN_CODE));
                                                obj.put("equipmentnum", SPUtil.getStringValue(SPUtil.PHONE_NAME));
                                                AppCache.getSignalRService().sendData(mMissionId, obj.toString());

//                                            bean.path = obj.getString();
//                                            bean.iswaiting=false;
//                                            adapter.notifyDataSetChanged();
                                                //showShortToast("上传中");
                                            } else {
                                                showShortToast(obj.getString(HttpConstant.FAIL_REASON));
                                            }
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                            showShortToast("服务器无响应");
                                        }
                                    }
                                }
                            });
                        }

                        @Override
                        public void onKeyUp() {
                            tvRecorder.setText("按住 说话");
                            EaseMessageAdapter.row += 2;
                        }

                        @Override
                        public void onMove(boolean isOut) {
                            if (isOut) {
                                tvRecorder.setText("松开手指，取消发送");
                            } else {
                                tvRecorder.setText("松开 结束");
                            }
                        }

                    });
                }
            });
            GetList();
            if (AppCache.getSignalRService()!=null) {
                AppCache.getSignalRService().joinRoom(mMissionId, SPUtil.getStringValue(SPUtil.USER_NAME));
                AppCache.getSignalRService().Subscribe();
            }
            Intent intent1 = new Intent();
            intent1.setClass(this.getActivity(), PlayService.class);
            mPlayServiceConnection = new PlayServiceConnection();
            ((VoiceActivity)this.getActivity()).setOnSelectedPhotoListener(new CallBackUtil.OnSelectedPhotoListener() {
                @Override
                public void onSelected(ArrayList<String> photos) throws FileNotFoundException {
//                    for(int i=0;i<photos.size();i++)
//                    {
//                        final MessageBean bean = new MessageBean();
//                        bean.path = "";
//                        bean.msg = SPUtil.getStringValue(SPUtil.USER_NAME);
//                        bean.time = System.currentTimeMillis();
//                        bean.datatype=2;
//                        bean.iswaiting = true;
//                        voices.add(bean);
//                        Bundle data = new Bundle();
//                        Message message1 = new Message();
//                        message1.setData(data);
//                    }


                    for (String pho :
                            photos) {


                        RequestParams params = new RequestParams("visit", "Upload");
                        params.put("FileData", new File(pho));
                        params.put("datatype","2");
                        params.put("usertype","1");
                        AsyncHttpUtil.postRequest(params, new TextHttpResponseHandler() {
                            @Override
                            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                                showShortToast("服务器无响应");
                            }

                            @Override
                            public void onSuccess(int i, Header[] headers, String s) {
                                //JLog.d(TAG, "Upload Result:" + s);
                                if (!TextUtils.isEmpty(s.toString())) {
                                    try {
                                        JSONObject obj = new JSONObject(s);
                                        if (obj.getBoolean(HttpConstant.RESPONSE_SUCCESS)) {

                                            obj.put("datatype","2");
                                            obj.put("username", SPUtil.getStringValue(SPUtil.USER_NAME));
                                            obj.put("companyname", SPUtil.getStringValue(SPUtil.LOGIN_CODE));
                                            obj.put("equipmentnum", SPUtil.getStringValue(SPUtil.PHONE_NAME));
                                            
                                            AppCache.getSignalRService().sendData(mMissionId, obj.toString());

//                                            bean.path = obj.getString();
//                                            bean.iswaiting=false;
//                                            adapter.notifyDataSetChanged();
                                            //showShortToast("上传中");
                                        } else {
                                            showShortToast(obj.getString(HttpConstant.FAIL_REASON));
                                        }
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                        showShortToast("服务器无响应");
                                    }
                                }
                            }
                        });
                    }

                }
            });
            playBind=this.getActivity().bindService(intent1, mPlayServiceConnection, Context.BIND_AUTO_CREATE);

        }
        catch(Exception e)
        {
            Log.d(TAG, "initViewByID: ",e );
        }

        //GetList();


    }


    protected void receiveMessageVoice()
    {
        if (mVoiceImpl == null) {
            mVoiceImpl = VoiceImpl.getInstance(getContext());
        }
        mVoiceImpl.addSound(R.raw.info_new_message);
        mVoiceImpl.playVoice();
    }

    protected void openNetwork() {
        MaterialDialog dialog = new MaterialDialog.Builder(this.getActivity())
                .content(R.string.dialog_content_open_network)
                .negativeText(R.string.dialog_positive_setting)
                .negativeColorRes(R.color.back_ground_green)
                .onNegative(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        // 跳转到系统的网络设置界面
                        Intent intent = null;
                        // 先判断当前系统版本
                        if (android.os.Build.VERSION.SDK_INT > 10) {  // 3.0以上
                            intent = new Intent(Settings.ACTION_SETTINGS);
                        } else {
                            intent = new Intent();
                            intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings");
                        }
                        startActivity(intent);
                    }
                })
                .build();
        ViewUtil.removeHomeKeyListener(dialog);
    }

    private Handler updateDateHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            //获取日期,显示
            Bundle bundle = msg.getData();
            adapter.notifyDataSetChanged();
            if (isFirst)
            {
                message_list.setSelection(message_list.getBottom());
                isFirst=false;
            }
        }
    };

    private Handler updateOnlieStateHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            //获取日期,显示
            Bundle bundle = msg.getData();
            boolean isOnline=bundle.getBoolean("isonline");
            if (isOnline){
                //dismissLoadingDialog();

                voiceRecorderView.setEnabled(true);
                mRequestMissionTip.setVisibility(View.GONE);
                mListItemContainer.setVisibility(View.VISIBLE);
            }
            else{
                voiceRecorderView.setEnabled(false);
                mRequestMissionTip.setVisibility(View.VISIBLE);
                mListItemContainer.setVisibility(View.GONE);
            }
        }
    };









}
